﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using LinqDll;

namespace LinqBll
{
    public class BaseCore<T>
        where T : class, new()
    {
        #region prop

        public DataContext Db
        {
            get { return _linqWrapper.Db; }
        }

        public Table<T> Table
        {
            get { return _linqWrapper.Table; }
        }
        #endregion

        #region method
        private readonly LinqWrapper<T> _linqWrapper;

        public BaseCore(DataContext dataContext)
        {
            _linqWrapper = new LinqWrapper<T>(dataContext);
        }

        public void CreateList(IEnumerable<T> ts)
        {
            _linqWrapper.CreateList(ts);
        }

        public void Create(T t)
        {
            _linqWrapper.Create(t);
        }

        public void Delete(T t)
        {
            _linqWrapper.Delete(t);
        }

        public void Update(T t)
        {
            _linqWrapper.Update(t);
        }

        public void Dispose()
        {
            _linqWrapper.Dispose();
        }

        public void Delete(IEnumerable<T> ts)
        {
            _linqWrapper.Delete(ts);
        }

        public void Update(IEnumerable<T> ts)
        {
            _linqWrapper.Update(ts);
        }

        public T FirstOrDefault()
        {
            return _linqWrapper.FirstOrDefault();
        }

        public T Query(Func<T, bool> func)
        {
            return _linqWrapper.Query(func);
        }

        public IQueryable<T> QueryList()
        {
            return _linqWrapper.QueryList();
        }

        public IQueryable<T> QueryList(Func<T, bool> func)
        {
            return _linqWrapper.QueryList(func);
        }

        public IQueryable<T> QueryList(Func<T, int, bool> func)
        {
            return _linqWrapper.QueryList(func);
        }

        public IQueryable<T> Pager(int skipNum, int takeNum)
        {
            return _linqWrapper.Pager(skipNum, takeNum);
        }
        #endregion
    }
}